import {defineStore} from "pinia"
import {ref,computed} from "vue"
// 引入获取当前用户权限的接口
import {getRolePermissionListApi} from "@/api/permission"

export default defineStore('permission',()=>{
    // 当前用户的权限
    let currentPermissions = ref([])
    // 获取当前用户权限的方法
    let getCurrentPermissions = async (currentRoleid) => {
        let res = await getRolePermissionListApi({type:'1',roleid:currentRoleid})
        currentPermissions.value = res.data.data
    }
    // 将当前角色的权限数据转换成id数组
    let currentPermissionsIds = computed(()=>{
        return currentPermissions.value.map(item=>item.id)
    })
    return {currentPermissions,getCurrentPermissions,currentPermissionsIds}
},{
    persist:true
})